package com.study.config;

import com.study.interceptor.ExecutorInterceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

@Configuration
public class MybatisInterceptorConfig {
    @Bean
    public String myInterceptor(SqlSessionFactory sqlSessionFactory) {
        ExecutorInterceptor executorInterceptor = new ExecutorInterceptor();
        Properties properties = new Properties();
        properties.setProperty("prop1","value1");
        executorInterceptor.setProperties(properties);
        //如果说不需要配置属性，则在spring boot中，不需要去编写配置类，只需要像我一样在拦截器上加个@Component即可。
        sqlSessionFactory.getConfiguration().addInterceptor(executorInterceptor);

        return "interceptor";
    }
}

